package org.lex.dbq.model.jdbc.sql;

import java.sql.Connection;
import java.sql.SQLException;

import org.lex.dbq.model.bo.SQLMetaData;
import org.lex.dbq.model.service.MetaDataService;
import org.lex.string.StringUtils;

public class SelectBuilder {
	public String buildSelectAll(Connection conn, String catalog, String schema, String table) throws SQLException {
		SQLMetaData md = MetaDataService.getInstance().get(conn);

		StringBuilder buf = new StringBuilder();
		buf.append("select * from ");
		if (false == StringUtils.isNullOrEmpty(catalog)) {
			buf.append(md.getIdentifierQuoteString());
			buf.append(catalog);
			buf.append(md.getIdentifierQuoteString());
			buf.append('.');
		}
		if (false == StringUtils.isNullOrEmpty(schema)) {
			buf.append(md.getIdentifierQuoteString());
			buf.append(schema);
			buf.append(md.getIdentifierQuoteString());
			buf.append('.');
		}
		buf.append(md.getIdentifierQuoteString());
		buf.append(table);
		buf.append(md.getIdentifierQuoteString());
		return buf.toString();
	}
}
